<?
include_once ('common.inc.php');
include ('db.inc.php');
function user_exists($email) {
	$email_str = mysql_real_escape_string($email);
	$result = mysql_query("select email from users where email=\"$email_str\"");
	if (!mysql_fetch_row($result)) return false;
	return true;
}

function check_input() {
	if ($_POST['email'] == null || trim($_POST['email']) == '') {
		return false;
	}
	return true;
}

//function send_activating_mail($email) {
//	
//	mysql_query("insert into users (email,passwd,reg_time,login_time) values (\"\",\"\",\"\",\"\")");
//}

function create_user($params) {
	$email = mysql_real_escape_string($params['email']);
	$passwd = md5(mysql_real_escape_string($params['passwd']));
	return mysql_query("insert into users (email,passwd) values (\"$email\",\"$passwd\")");
}

include ('head.inc.php');
if (!check_input()) {
	error(_('invalid input'));
}
if (user_exists($_POST['email'])) {
	error(_("The user has exists"));
}

create_user($_POST) or error(_("db error"));

redirect("apiintro.php");
?>
